package com.ttg.utils.connection;

//~--- non-JDK imports --------------------------------------------------------

import com.ttg.utils.Assert;

import java.io.File;

//~--- JDK imports ------------------------------------------------------------

/**
 * Class	HttpUploadFile
 * Description	
 * Create	2015.09.11 at 01:24:06 CST
 * @author	Ardy    
 */
public class HttpUploadFile {

    /** 
     * Field parameterName
     * Description 
     */
    private final String parameterName;

    /** 
     * Field fileName
     * Description 
     */
    private final String fileName;

    /** 
     * Field file
     * Description 
     */
    private File file;

    /** 
     * Field content
     * Description 
     */
    private byte[] content;

    /**
     * Constructs	HttpUploadFile
     * Description
     *
     * @param parameterName
     * @param fileName
     * @param file
     * @param content
     */
    public HttpUploadFile(String parameterName, String fileName, File file, byte[] content) {
        Assert.hasText(parameterName);
        this.parameterName = parameterName;
        Assert.hasText(fileName);
        this.fileName = fileName;

        if ((file != null) && (content != null)) {
            throw new IllegalArgumentException("File文件和byte[]内容只能存在一个!");
        } else if ((file == null) && (content == null)) {
            throw new IllegalArgumentException("File文件和byte[]内容都为null,至少要存在一个!");
        } else if ((content != null) || ((file != null) && (!file.exists() ||!file.isDirectory()))) {
            this.file    = file;
            this.content = content;
        } else {
            throw new IllegalArgumentException("file[" + file.getAbsolutePath() + "]必须是一个不存在的文件,不能为null,且不能是一个已存在的目录");
        }
    }

    /**
     * Method getParameterName
     * Description
     * @return	String
     */
    public String getParameterName() {
        return this.parameterName;
    }

    /**
     * Method getFileName
     * Description
     * @return	String
     */
    public String getFileName() {
        return this.fileName;
    }

    /**
     * Method getFile
     * Description
     * @return	File
     */
    public File getFile() {
        return this.file;
    }

    /**
     * Method getContent
     * Description
     * @return	byte[]
     */
    public byte[] getContent() {
        return this.content;
    }

    /**
     * Method setFile
     * Description
     *
     * @param	file File
     */
    public void setFile(File file) {
        this.file = file;
    }

    /**
     * Method setContent
     * Description
     *
     * @param	content byte[]
     */
    public void setContent(byte[] content) {
        this.content = content;
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
